package org.dkakunsi.aplikasitoko.form.kasir;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;

import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JRViewer;

import org.dkakunsi.aplikasitoko.data.entity.Transaksi;
import org.dkakunsi.aplikasitoko.service.ReportService;

public class PanelStruk extends JInternalFrame implements ActionListener {

	private static final long serialVersionUID = 1L;
	
	private JPanel pnlReport;
	private Transaksi transaksi;

	public PanelStruk(Transaksi transaksi) {
		super();
		getContentPane().setLayout(null);
		setBounds(100, 100, 800, 600);

		JButton btnOK = new JButton("KELUAR");
		btnOK.setBounds(10, 520, 100, 25);
		getContentPane().add(btnOK);
		btnOK.setActionCommand("OK");
		btnOK.addActionListener(this);

		pnlReport = new JPanel();
		pnlReport.setBounds(10, 12, 770, 500);
		pnlReport.setLayout(new BorderLayout(0, 0));
		getContentPane().add(pnlReport);
		
		this.transaksi = transaksi;
		initReport();
	}
	
	private void initReport() {
		JasperPrint print = ReportService.getReport(this.transaksi);
		JRViewer viewer = new JRViewer(print);
		pnlReport.removeAll();
		pnlReport.add(viewer,BorderLayout.CENTER);
		pnlReport.updateUI();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		String cmd = e.getActionCommand();
		
		if(cmd.equals("OK")) {
			dispose();
		}
		
	}
	
}
